word_to_num = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}

user_input = input().split()
if len(user_input) != 3:
    print("Wrong input")
else:
    try:
        num = int(''.join(str(word_to_num[word]) for word in user_input))
        lower_prime = num
        upper_prime = num
        while True:
            is_prime = True
            if lower_prime < 2:
                is_prime = False
            else:
                for i in range(2, int(lower_prime**0.5) + 1):
                    if lower_prime % i == 0:
                        is_prime = False
                        break
            if is_prime:
                break
            lower_prime -= 1
        while True:
            is_prime = True
            if upper_prime < 2:
                is_prime = False
            else:
                for i in range(2, int(upper_prime**0.5) + 1):
                    if upper_prime % i == 0:
                        is_prime = False
                        break
            if is_prime:
                break
            upper_prime += 1
        
        if upper_prime - num >= num - lower_prime:
            print(lower_prime)
        else:
            print(upper_prime)
    except (KeyError, ValueError):
        print("Wrong input")